package jmine.tec.web.front.sample.extensions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jmine.tec.web.front.sample.extensions.rs.SampleForm;

/**
 * @author lundberg
 */
public class SampleFormHandlerImpl implements SampleFormHandler {

    private List<SampleForm> appliedForms = new ArrayList<SampleForm>();

    /**
     * {@inheritDoc}
     */
    public List<String> validate(SampleForm form) {
        List<String> errors = new ArrayList<String>();
        if (form.getImportantString() == null) {
            errors.add("Important String is Null!");
        }
        if (form.getImportantNumber() == null) {
            errors.add("Important Number is Null!");
        }
        if (form.getImportantDate() == null) {
            errors.add("Important Date is Null!");
        }
        return errors;
    }

    /**
     * {@inheritDoc}
     */
    public void apply(SampleForm form) {
        this.appliedForms.add(form);
    }

    public List<SampleForm> getAppliedForms() {
        return Collections.unmodifiableList(this.appliedForms);
    }

    public void clear() {
        this.appliedForms.clear();
    }

    public Class<SampleForm> formClass() {
        return SampleForm.class;
    }

}
